<template>
	<view class="content">
		<view class="title" style="margin-top: 200rpx;">您的生日是？</view>

		<picker-view :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view"
			mask-style="background:transparent;" >
			<picker-view-column>
				<view class="item" :class="{ select: item == year }" v-for="(item, index) in years" :key="index">
					{{ item }}年
				</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" :class="{ select: item == month }" v-for="(item, index) in months" :key="index">
					{{ item }}月
				</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" :class="{ select: item == day }" v-for="(item, index) in days" :key="index">
					{{ item }}日
				</view>
			</picker-view-column>
		</picker-view>
		
		<view class="bottom" style="margin-top: 260rpx;">
			<view @click="back">
				<u-icon name="arrow-leftward" color="#222" size="50"></u-icon>
			</view>
			<view class="btn" @click="next">
				<view class="bin-confirm">OK了</view>
				<u-icon name="arrow-rightward" color="#fff" size="28"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const date = new Date();
			const years = [];
			const year = date.getFullYear();
			const months = [];
			const month = date.getMonth() + 1;
			const days = [];
			const day = date.getDate();
			for (let i = 1900; i <= date.getFullYear() - 18; i++) {
				years.push(i);
			}
			for (let i = 1; i <= 12; i++) {
				months.push(i);
			}
			for (let i = 1; i <= 31; i++) {
				days.push(i);
			}
			return {
				// $c: this.$common,
				// title: 'picker-view',
				years,
				year,
				months,
				month,
				days,
				day,
				value: [years.length - 1, month - 1, day - 1],
				indicatorStyle: `height: 50px`,
				// current: 0,
				// swiperHeight: 0,
				data: {
					device: '478ca4671a993355',
					sex: '',
					nickname: '',
					birthday: '',
					height: '',
					weight: '',
					career: '',
					income: '',
					save_city: '',
					avatar: '',
					phone: '',
					code: '',
					password: '',
				}
			};
		},
		onLoad() {
			this.data = uni.getStorageSync('registerInfo');
			this.$nextTick(() => {
				let e = {
					detail: {
						value: this.value
					}
				};
				this.bindChange(e);
			});
		},
		methods: {
			back(){
				uni.navigateBack();
			},
			async next() {
				let res = await this.$common.post('/app/login/completeMaterial?nicheng=' + this.data.nickname +
					'&sex=' + this.data.sex +
					'&shengri=' + this.data.birthday);

				uni.setStorageSync('registerInfo', this.data);
				uni.navigateTo({
					url: "/pages/register/register3"
				})
			},
			bindChange: function(e) {
				const val = e.detail.value;
				this.year = this.years[val[0]];
				this.month = this.months[val[1]];
				this.day = this.days[val[2]];
				this.data.birthday = this.years[val[0]] + '-' + this.months[val[1]] + '-' + this.days[val[2]];
				console.log(this.data.birthday);
			}
		}
	};
</script>

<style lang="scss">
	.content {
		width: 100wh;
		height: 100vh;
		margin: 0 50rpx;

		.title {
			font-weight: bold;
			font-size: 48rpx;
			color: #222;
		}
		
		.bottom {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
		
			.btn {
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				width: 150rpx;
				height: 80rpx;
				background-color: #222;
				border-radius: 10rpx;
		
				.bin-confirm {
					color: white;
					font-size: 24rpx;
				}
			}
		}

		.picker-view {
			width: 100%;
			height: 600rpx;
			margin: 0 auto;
		}
		
		.item {
			height: 50px;
			line-height: 50px;
			// align-items: center;
			// justify-content: center;
			text-align: center;
			color: #999;
		}
		
		.item.select {
			color: #222;
			font-size: 36rpx;
			font-weight: 600;
		}

		// .picker-view /deep/.uni-picker-view-mask,
		// .picker-view .uni-picker-view-mask {
		// 	background: transparent;
		// }

		// .picker-view /deep/.uni-picker-view-indicator {
		// 	border-top: 2rpx solid #ccc;
		// 	border-bottom: 2rpx solid #ccc;
		// }
		
		
	}
</style>